
const USER_INFO_KEY = 'hm_shopping_user_info'
const SEARCH_HISTORY_KEY = 'hm_shopping_search_history'

// 用户信息相关
export const getUserInfo = () => {
  const result = localStorage.getItem(USER_INFO_KEY)
  return result ? JSON.parse(result) : { userId: '', token: '' }
}

export const setUserInfo = (obj) => {
  localStorage.setItem(USER_INFO_KEY, JSON.stringify(obj))
}

export const removeUserInfo = () => {
  localStorage.removeItem(USER_INFO_KEY)
}

// 搜索历史记录相关
export const getSearchList = () => {
  const result = localStorage.getItem(SEARCH_HISTORY_KEY)
  return result ? JSON.parse(result) : []
}

export const setSearchList = (arr) => {
  localStorage.setItem(SEARCH_HISTORY_KEY, JSON.stringify(arr))
}
